/*
 * PanelReplayControls.java
 *
 * Created on March 22, 2008, 3:01 PM
 */
package hextd.UI;

import hextd.HexTD;
import hextd.HexTD.GameState;
import hextd.blackBox.BBAction;
import hextd.blackBox.BBActionListener;
import hextd.blackBox.BlackBox;
import hextd.core.Context.GameTime;
import hextd.core.ContextNormal;
import hextd.core.MapInfo;
import java.io.BufferedReader;
import java.io.StringReader;
import javax.swing.SpinnerNumberModel;

/**
 *
 * @author  hylke
 */
public class PanelReplayControls extends javax.swing.JPanel implements BBActionListener {

	private ContextNormal context;
	private HexTD mainGame;
	private BlackBox blackBoxRecord;
	private BlackBox blackBoxPlayback;
	private boolean runTill = false;
	private boolean runTillWave = false;
	private int runTillWaveNr = 0;
	private BlackBox.ActionType runTillType;
	private static String textGo = "Go";
	private static String textStop = "Stop";

	/** Creates new form PanelReplayControls */
	public PanelReplayControls() {
		this.setVisible(false);
	}

	public void setContext(ContextNormal c, HexTD mainGame) {
		this.context = c;
		this.mainGame = mainGame;
		initComponents();
	}

	public void setBlackBox(BlackBox record, BlackBox playback) {
		if (this.blackBoxPlayback != null) {
			this.blackBoxPlayback.removeBBActionListener(this);
		}
		this.blackBoxPlayback = playback;
		this.blackBoxRecord = record;
		this.blackBoxPlayback.addBBActionListener(this);
		this.jLabel_actionPointerPlay.setText("" + this.blackBoxPlayback.getActionPointer());
	}

	@Override
	public void ActionExecuted(BBAction action) {
		this.jLabel_actionPointerPlay.setText("" + this.blackBoxPlayback.getActionPointer());
		if (this.runTill) {
			if (this.runTillType == action.getType()) {
				if (this.runTillWave) {
					if (this.context.getWave() <= this.runTillWaveNr) {
						return;
					}
				}
				this.mainGame.maxGameSpeed(false);
				if (this.jCheckBox_skipPause.isSelected()) {
					this.mainGame.togglePause();
				}
				this.runTill = false;
				this.jButton_skipOn.setText(PanelReplayControls.textGo);
			}
		}
	}

	@Override
	public void ActionCountChanged() {
		this.jLabel_actionCountPlay.setText("" + this.blackBoxPlayback.getActionCount());
		SpinnerNumberModel model = (SpinnerNumberModel) this.jSpinner_waveNr.getModel();
		model.setMaximum(this.blackBoxPlayback.getNextWaveActionCount());
		this.jPanel1.repaint();
		this.jLabel_actionPointerPlay.setText("" + this.blackBoxPlayback.getActionPointer());
	}

	public void loadReplay(String replay) {
		GameTime gt = context.getGameTime();
		context.getGameLoop().stopGameLoop();
		synchronized (gt) {
			context.setPause(true, false);
			gt.reset();
			blackBoxPlayback.clear();
			blackBoxPlayback.loadLog(new BufferedReader(new StringReader(replay)));
			blackBoxRecord.clear();
			context.setGameState(HexTD.GameState.replaying);
			context.setGameResult(HexTD.GameResult.active);
			mainGame.setUI();
		}
		context.getGameLoop().startGameLoop();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        buttonGroup1 = new javax.swing.ButtonGroup();
        jFrame1 = new javax.swing.JFrame();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane_output = new javax.swing.JTextPane();
        jButton_loadReplay = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jButton_skipOn = new javax.swing.JButton();
        jCheckBox_skipPause = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        jSpinner_waveNr = new javax.swing.JSpinner();
        jRadioButton_nextWave = new javax.swing.JRadioButton();
        jRadioButton_end = new javax.swing.JRadioButton();
        jRadioButton_skipWaveNr = new javax.swing.JRadioButton();
        jRadioButtonTick = new javax.swing.JRadioButton();
        jSpinnerTick = new javax.swing.JSpinner();
        jPanel4 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton100 = new javax.swing.JButton();
        jButton_print = new javax.swing.JButton();
        jButton_load = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel_actionCountPlay = new javax.swing.JLabel();
        jLabel_actionPointerPlay = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton_pause = new javax.swing.JButton();
        jButton_play = new javax.swing.JButton();

        jFrame1.getContentPane().setLayout(new java.awt.GridBagLayout());

        jScrollPane2.setMinimumSize(new java.awt.Dimension(200, 200));
        jScrollPane2.setPreferredSize(new java.awt.Dimension(200, 200));
        jScrollPane2.setViewportView(jTextPane_output);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 0.01;
        jFrame1.getContentPane().add(jScrollPane2, gridBagConstraints);

        jButton_loadReplay.setText("Load Replay");
        jButton_loadReplay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_loadReplayActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.01;
        jFrame1.getContentPane().add(jButton_loadReplay, gridBagConstraints);

        setBackground(context.colors.getColorBackGround());
        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Replay", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Bitstream Vera Sans", 0, 13), context.colors.getColorForeGround())); // NOI18N
        setForeground(context.colors.getColorForeGround());
        setLayout(new java.awt.GridBagLayout());

        jPanel1.setBackground(context.colors.getColorBackGround());
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Skip till", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Bitstream Vera Sans", 0, 13), context.colors.getColorForeGround())); // NOI18N
        jPanel1.setForeground(context.colors.getColorForeGround());
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jButton_skipOn.setBackground(context.colors.getColorBackGround());
        jButton_skipOn.setForeground(context.colors.getColorForeGround());
        jButton_skipOn.setText(this.textGo);
        jButton_skipOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_skipOnActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel1.add(jButton_skipOn, gridBagConstraints);

        jCheckBox_skipPause.setBackground(context.colors.getColorBackGround());
        jCheckBox_skipPause.setForeground(context.colors.getColorForeGround());
        jCheckBox_skipPause.setText("and Pause");
        jCheckBox_skipPause.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel1.add(jCheckBox_skipPause, gridBagConstraints);

        jPanel2.setBackground(context.colors.getColorBackGround());
        jPanel2.setForeground(context.colors.getColorForeGround());
        jPanel2.setLayout(new java.awt.GridBagLayout());

        jSpinner_waveNr.setBackground(context.colors.getColorBackGround());
        jSpinner_waveNr.setForeground(context.colors.getColorForeGround());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jSpinner_waveNr, gridBagConstraints);

        jRadioButton_nextWave.setBackground(context.colors.getColorBackGround());
        buttonGroup1.add(jRadioButton_nextWave);
        jRadioButton_nextWave.setForeground(context.colors.getColorForeGround());
        jRadioButton_nextWave.setSelected(true);
        jRadioButton_nextWave.setText("Next Wave");
        jRadioButton_nextWave.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jRadioButton_nextWave, gridBagConstraints);

        jRadioButton_end.setBackground(context.colors.getColorBackGround());
        buttonGroup1.add(jRadioButton_end);
        jRadioButton_end.setForeground(context.colors.getColorForeGround());
        jRadioButton_end.setText("End");
        jRadioButton_end.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jRadioButton_end, gridBagConstraints);

        jRadioButton_skipWaveNr.setBackground(context.colors.getColorBackGround());
        buttonGroup1.add(jRadioButton_skipWaveNr);
        jRadioButton_skipWaveNr.setForeground(context.colors.getColorForeGround());
        jRadioButton_skipWaveNr.setText("Wave nr:");
        jRadioButton_skipWaveNr.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jRadioButton_skipWaveNr, gridBagConstraints);

        jRadioButtonTick.setBackground(context.colors.getColorBackGround());
        buttonGroup1.add(jRadioButtonTick);
        jRadioButtonTick.setForeground(context.colors.getColorForeGround());
        jRadioButtonTick.setText("Tick nr:");
        jRadioButtonTick.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jRadioButtonTick, gridBagConstraints);

        jSpinnerTick.setBackground(context.colors.getColorBackGround());
        jSpinnerTick.setForeground(context.colors.getColorForeGround());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jSpinnerTick, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        jPanel1.add(jPanel2, gridBagConstraints);

        jPanel4.setLayout(new java.awt.GridBagLayout());

        jButton1.setBackground(context.colors.getColorBackGround());
        jButton1.setForeground(context.colors.getColorForeGround());
        jButton1.setText(">1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        jPanel4.add(jButton1, gridBagConstraints);

        jButton10.setBackground(context.colors.getColorBackGround());
        jButton10.setForeground(context.colors.getColorForeGround());
        jButton10.setText(">10");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        jPanel4.add(jButton10, gridBagConstraints);

        jButton100.setBackground(context.colors.getColorBackGround());
        jButton100.setForeground(context.colors.getColorForeGround());
        jButton100.setText(">100");
        jButton100.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton100ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        jPanel4.add(jButton100, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        jPanel1.add(jPanel4, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 1.0E-6;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        add(jPanel1, gridBagConstraints);

        jButton_print.setBackground(context.colors.getColorBackGround());
        jButton_print.setForeground(context.colors.getColorForeGround());
        jButton_print.setText("Print");
        jButton_print.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_printActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jButton_print, gridBagConstraints);

        jButton_load.setBackground(context.colors.getColorBackGround());
        jButton_load.setForeground(context.colors.getColorForeGround());
        jButton_load.setText("Load");
        jButton_load.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_loadActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jButton_load, gridBagConstraints);

        jPanel3.setBackground(context.colors.getColorBackGround());
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Playback", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Bitstream Vera Sans", 0, 13), context.colors.getColorForeGround())); // NOI18N
        jPanel3.setForeground(context.colors.getColorForeGround());
        jPanel3.setLayout(new java.awt.GridBagLayout());

        jLabel1.setBackground(context.colors.getColorBackGround());
        jLabel1.setForeground(context.colors.getColorForeGround());
        jLabel1.setText("Actions:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
        jPanel3.add(jLabel1, gridBagConstraints);

        jLabel_actionCountPlay.setBackground(context.colors.getColorBackGround());
        jLabel_actionCountPlay.setForeground(context.colors.getColorForeGround());
        jLabel_actionCountPlay.setText("0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
        jPanel3.add(jLabel_actionCountPlay, gridBagConstraints);

        jLabel_actionPointerPlay.setBackground(context.colors.getColorBackGround());
        jLabel_actionPointerPlay.setForeground(context.colors.getColorForeGround());
        jLabel_actionPointerPlay.setText("0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
        jPanel3.add(jLabel_actionPointerPlay, gridBagConstraints);

        jLabel2.setBackground(context.colors.getColorBackGround());
        jLabel2.setForeground(context.colors.getColorForeGround());
        jLabel2.setText("Next:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
        jPanel3.add(jLabel2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        add(jPanel3, gridBagConstraints);

        jButton_pause.setBackground(context.colors.getColorBackGround());
        jButton_pause.setForeground(context.colors.getColorForeGround());
        jButton_pause.setMnemonic('P');
        jButton_pause.setText("Pause");
        jButton_pause.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_pauseActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jButton_pause, gridBagConstraints);

        jButton_play.setBackground(context.colors.getColorBackGround());
        jButton_play.setForeground(context.colors.getColorForeGround());
        jButton_play.setText("Go Play");
        jButton_play.setToolTipText("Leave recording centre and play from this point.");
        jButton_play.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_playActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jButton_play, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents
    private void jButton_playActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_playActionPerformed
		mainGame.setPause(true, false);
		MapInfo mapInfo = context.getMapInfo();
		if (mapInfo.waves > 0) {
			context.setGameState(GameState.spPlaying);
		} else {
			context.setGameState(GameState.spPlayingWaveless);
		}
    }//GEN-LAST:event_jButton_playActionPerformed

    private void jButton_pauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_pauseActionPerformed
		this.mainGame.togglePause();
    }//GEN-LAST:event_jButton_pauseActionPerformed

    private void jButton_printActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_printActionPerformed
		this.jTextPane_output.setText(this.blackBoxPlayback.printLog().toString());
		this.jFrame1.setVisible(true);
		this.jFrame1.pack();
    }//GEN-LAST:event_jButton_printActionPerformed

    private void jButton_loadReplayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_loadReplayActionPerformed
		this.jFrame1.setVisible(false);
		loadReplay(this.jTextPane_output.getText());
    }//GEN-LAST:event_jButton_loadReplayActionPerformed

    private void jButton_loadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_loadActionPerformed
		this.jFrame1.pack();
		this.jFrame1.setVisible(true);

    }//GEN-LAST:event_jButton_loadActionPerformed

    private void jButton_skipOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_skipOnActionPerformed
		if (runTill) {
			mainGame.maxGameSpeed(false);
			runTill = false;
			jButton_skipOn.setText(PanelReplayControls.textGo);
		} else {
			jButton_skipOn.setText(PanelReplayControls.textStop);
			runTillWave = false;
			if (jRadioButton_nextWave.isSelected()) {
				runTillType = BlackBox.ActionType.NextWave;
				runTill = true;
				mainGame.maxGameSpeed(true);
				mainGame.setPause(false, false);
				return;
			} else if (this.jRadioButton_skipWaveNr.isSelected()) {
				try {
					runTillWaveNr = new Integer(this.jSpinner_waveNr.getValue().toString()).intValue();
					runTillType = BlackBox.ActionType.NextWave;
					runTill = true;
					runTillWave = true;
					mainGame.maxGameSpeed(true);
					mainGame.setPause(false, false);
					return;
				} catch (NumberFormatException ex) {
					ex.printStackTrace();
				}
			} else if (jRadioButton_end.isSelected()) {
				runTillType = BlackBox.ActionType.End;
				runTill = true;
				mainGame.maxGameSpeed(true);
				mainGame.setPause(false, false);
				return;
			} else if (jRadioButtonTick.isSelected()) {
				runTillType = BlackBox.ActionType.End;
				runTill = true;
				int runToTick = new Integer(jSpinnerTick.getValue().toString()).intValue();
				context.getGameLoop().setPauseAtTick(runToTick);
				mainGame.maxGameSpeed(true);
				mainGame.setPause(false, false);
				return;
			}
		}
		jButton_skipOn.setText(PanelReplayControls.textGo);

    }//GEN-LAST:event_jButton_skipOnActionPerformed

	private void skipNTicks(int n) {
		jButton_skipOn.setText(PanelReplayControls.textStop);
		runTillType = BlackBox.ActionType.End;
		runTill = true;
		int runToTick = context.getGameTime().getTime() + n;
		context.getGameLoop().setPauseAtTick(runToTick);
		mainGame.maxGameSpeed(true);
		mainGame.setPause(false, false);
	}

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
		skipNTicks(1);
	}//GEN-LAST:event_jButton1ActionPerformed

	private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
		skipNTicks(10);
}//GEN-LAST:event_jButton10ActionPerformed

	private void jButton100ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton100ActionPerformed
		skipNTicks(100);
}//GEN-LAST:event_jButton100ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton100;
    private javax.swing.JButton jButton_load;
    private javax.swing.JButton jButton_loadReplay;
    private javax.swing.JButton jButton_pause;
    private javax.swing.JButton jButton_play;
    private javax.swing.JButton jButton_print;
    private javax.swing.JButton jButton_skipOn;
    private javax.swing.JCheckBox jCheckBox_skipPause;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel_actionCountPlay;
    private javax.swing.JLabel jLabel_actionPointerPlay;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JRadioButton jRadioButtonTick;
    private javax.swing.JRadioButton jRadioButton_end;
    private javax.swing.JRadioButton jRadioButton_nextWave;
    private javax.swing.JRadioButton jRadioButton_skipWaveNr;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSpinner jSpinnerTick;
    private javax.swing.JSpinner jSpinner_waveNr;
    private javax.swing.JTextPane jTextPane_output;
    // End of variables declaration//GEN-END:variables
}
